home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1988 September
/
Ahoy_Magazine_88-09_1988_Double_L.d64
/
double sort
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
882b
|
25 lines
0 print"[147] double sort":print
1 rem =================================
2 rem commodares problem #51-2 :
3 rem double sort
4 rem solution by
5 rem jim speers
6 rem =================================
100 dim w$(20),s$(20)
110 n=n+1: if n>20 then n=n-1: goto 140
120 input"enter word";w$(n): if w$(n)="^" then n=n-1: goto 140
130 goto 110
140 for i=1 to n: s$(i)=w$(i): next
150 for i=1 to n: x$=w$(i): l=len(x$): if l=1 then 200
160 for j=1 to l-1: for k=j to l
170 if mid$(x$,j,1)<mid$(x$,k,1) then 190
180 t$=mid$(x$,j,1): mid$(x$,j,1)=mid$(x$,k,1): mid$(x$,k,1)=t$
190 next k,j: w$(i)=x$
200 next i: for i=1 to n-1: for j=i+1 to n
210 if len(w$(i))<=len(w$(j)) then 230
220 t$=w$(i): w$(i)=w$(j): w$(j)=t$: t$=s$(i): s$(i)=s$(j): s$(j)=t$
230 next j,i: for i=1 to n-1: for j=i+1 to n
240 if (w$(i)<w$(j)) or (len(w$(i))<>len(w$(j))) then 260
250 t$=w$(i): w$(i)=w$(j): w$(j)=t$: t$=s$(i): s$(i)=s$(j): s$(j)=t$
260 next j,i: print"[147]": for i=1 to n: print w$(i)tab(18)s$(i): next